package com.ize.controller.student;

import com.ize.entity.dto.UserLoginDto;
import com.ize.entity.dto.UserLoginInfoDto;
import com.ize.entity.pojo.User;
import com.ize.entity.vo.UserLoginStateVo;
import com.ize.entity.vo.UserLoginVO;
import com.ize.result.Result;
import com.ize.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
@Slf4j
@Api(tags = "微信学生端相关接口")
@RequiredArgsConstructor
public class StudentConntroller {

    private final StudentService studentService;


    /**
     * 微信一键登录
     * @param userLoginDto
     * @return
     */
    @PostMapping("/login0")
    @ApiOperation("微信一键登录")
    public Result login0(@RequestBody UserLoginDto userLoginDto) {
        log.info("微信登录{}--》",userLoginDto);
        UserLoginVO user = studentService.login0(userLoginDto);
        return Result.success(user);
    }

    @PostMapping("/login1")
    @ApiOperation("和微信绑定信息")
    public Result<UserLoginStateVo> login1(@RequestBody UserLoginInfoDto userLoginInfoDto) {
        log.info("审核信息{}",userLoginInfoDto);
        UserLoginStateVo userID = studentService.login1(userLoginInfoDto);
        return Result.success(userID);
    }

    @GetMapping("/state")
    @ApiOperation("获取账号状态")
    public Result<UserLoginStateVo> state(@RequestParam String code) {
        log.info("获取状态{}",code);
        UserLoginStateVo user = studentService.state(code);
        return Result.success(user);
    }

    @GetMapping("/info")
    @ApiOperation("获取学生信息")
    public Result<User> info() {
        log.info("正在获取学生信息......");
        User user = studentService.info();
        return Result.success(user);
    }
}
